package com.example.traning.spring.ioc.anno;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @author lei yu
 * @since 2025/04/22
 */
@Configuration
@PropertySource("classpath:db.properties")
public class IocJavaConfig {


    @Bean
    public Dog dog() {
        return new Dog().setName("小黄");
    }

    @Value("${mysql.url}")
    private String url;
    @Value("${mysql.user}")
    private String user;
    @Value("${mysql.password}")
    private String password;
    @Value("${mysql.driver}")
    private String driver;


    @Bean
    public DataSource dataSource() {

        DruidDataSource ds = new DruidDataSource();
        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(password);
        ds.setDriverClassName(driver);
        return ds;
    }
}
